package com.li.test.base;

import java.util.concurrent.TimeUnit;

public class WaitSleep {
    int wnum = 1;
    int snum = 1;
    public synchronized void waitfunc(){
        wnum++;
        System.out.println("线程名wait："+Thread.currentThread().getName());
        try {
            wait();
            System.out.println("线程名wait结束："+Thread.currentThread().getName());

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public void sleepfunc(){
        snum++;
        System.out.println("线程名sleep："+Thread.currentThread().getName());
        try{
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        WaitSleep ws = new WaitSleep();
        for (int i=1;i<=20;i++){
            new Thread(()->{
                ws.waitfunc();
                ws.sleepfunc();
            }).start();
        }

    }
}
